package com.google.jacli;

import java.lang.reflect.Field;
import java.util.List;

import com.google.jacli.compiler.AbstractCompiler;
import com.google.jacli.compiler.OptionCompiler;
import com.google.jacli.compiler.SequenceCompiler;

public enum Pattern {

    SEQ {
        void compile(final List<Field> fieldList, final Object target, final String[] args) {
            AbstractCompiler compiler = new SequenceCompiler();
            compiler.setPrefix(getPrefix());
            compiler.setShortPrefix(getShortPrefix());
            compiler.setCommand(command);
            compiler.compile(fieldList, target, args);
        }
    },
    OPT {
        void compile(final List<Field> fieldList, final Object target, final String[] args) {
            AbstractCompiler compiler = new OptionCompiler();
            compiler.setPrefix(getPrefix());
            compiler.setShortPrefix(getShortPrefix());
            compiler.setCommand(command);
            compiler.compile(fieldList, target, args);
        }
    };

    private static CommandLine command;    

    abstract void compile(final List<Field> fieldList, final Object target, final String[] args);


    public String getPrefix() {
        if (command != null) {
            return command.getPrefix();
        } else {
            return CommandLineParser.DEFAULT_PREFIX;
        }
    }

    public String getShortPrefix() {
        if (command != null) {
            return command.getShortPrefix();
        } else {
            return CommandLineParser.DEFAULT_SHORT_PREFIX;
        }
    }

    public static void setCommandLine(CommandLine c) {
        command = c;
    }
}